package com.iap.admin.service
{
	import com.iap.app.data.IAppData;
	import com.iap.app.model.ServiceResponse;
	import com.iap.admin.event.LoginEvent;
	import com.iap.common.translator.UserTranslator;
	
	import org.robotlegs.mvcs.Actor;
	
	public class LoginService extends Actor implements ILoginService
	{
		[Inject]
		public var data:IAppData;

		public function login(userName:String, userPass:String):void
		{
			data.dataComplete.add(responseHandler);
			data.login(userName, userPass);
		}

		private function responseHandler(response:ServiceResponse):void
		{
			data.dataComplete.remove(responseHandler);
			response.task = "";
			response.result = UserTranslator.translate(response.result);
			dispatch(new LoginEvent(LoginEvent.RESPONSE, response));
		}
	}
}